﻿using System;
using System.Collections.Generic;

namespace Geometry
{
    public class Polygon : LineString
    {
        #region 字段属性
        public List<string> LineStringIDList { get; set; }
        #endregion

        #region 构造器
        /// <summary>
        /// 点串构造法
        /// </summary>
        /// <param name="pointList">点集</param>
        public Polygon(List<Point> pointList)
        {
            Point pointFrom = pointList[0];
            Point pointTo = pointList[pointList.Count - 1];
            if (pointFrom.Equals(pointTo) && pointList.Count > 3)
                PointList = pointList;
            else
                Console.WriteLine("面必须有4个点以上且闭合！");
        }

        /// <summary>
        /// 点串构造法
        /// </summary>
        /// <param name="id">多边形ID</param>
        /// <param name="pointList">点集</param>
        public Polygon(string id, List<Point> pointList)
        {
            Point pointFrom = pointList[0];
            Point pointTo = pointList[pointList.Count - 1];
            if (pointFrom.Equals(pointTo))
            {
                this.id = id;
                PointList = pointList;
            }
            else
                Console.WriteLine("面必须有4个点以上且闭合！");
        }

        /// <summary>
        /// 折线索引构造法
        /// </summary>
        /// <param name="id"></param>
        /// <param name="lineStringIDs"></param>
        public Polygon(string id,List<string> lineStringIDs)
        {
            this.id = id;
            LineStringIDList.AddRange(lineStringIDs);
        }

        /// <summary>
        /// 折线闭合
        /// </summary>
        /// <param name="id">多边形ID</param>
        /// <param name="lineString"></param>
        public Polygon(string id, LineString lineString)
        {
            if (lineString.PointList.Count > 3)
            {
                PointList = lineString.PointList;
                PointList.Add(lineString.PointList[0]);
            }
            else
                Console.WriteLine("面必须有4个点以上且闭合！");

        }

        public Polygon() { }
        #endregion
    }


}
